var app = getApp();

Page({
    data: {
        imgUrl:app.globalData.imgUrl,
        msgList:[],
        msgArr:"",
        msgLength:"",
        pageCurrent:1,
        pageNum:"",  //总页数
        loading:false,   //"上拉加载中"
        loadingComplete:false,   //"加载完成"
    },
    onLoad: function () {
        var that = this;
        that.setData({
           navH: app.globalData.navHeight,
           marH: app.globalData.navHeight+20,
           token:wx.getStorageSync('token')
        })
        that.getMsg();
    },
    navBack: function () {
        wx.navigateBack({
          delta: 1
        })
    },
    getMsg:function(){
        var that=this;
        wx.request({
            url: app.globalData.apiHost + "/api/notice/list",
            data: {
                token: that.data.token,
                page: that.data.pageCurrent,
                pagesize:6
            },
            header: {  
                'content-type': 'application/x-www-form-urlencoded',
                'Cookie':'token='+that.data.token
            },
            method: "POST",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    var listLength=res.data.data.data.length;
                    var listPageNum = res.data.data.last_page;
                    for (var i = 0; i < res.data.data.data.length; i++) { 
                        that.data.msgList.push(res.data.data.data[i]);
                    }
                    var msgData = that.data.msgList;
                    that.setData({
                        msgArr: msgData,
                        pageNum:listPageNum,
                        msgLength:listLength
                    })
                }
            },
            
        });
    },
    onReachBottom: function () {
        let that = this;
        if (that.data.pageCurrent < that.data.pageNum) {
            that.setData({
                loading:true,
                loadingComplete:false,
                pageCurrent: that.data.pageCurrent + 1
            })
            that.getMsg();
        }else if(that.data.pageCurrent >= that.data.pageNum){
            that.setData({
                loading:false,
                loadingComplete:true
            })
        }
    }
})
